package edu.stu.book.book.keeping.viewmodel

import androidx.lifecycle.ViewModel
import edu.stu.book.book.keeping.db.dao.Cost
import edu.stu.book.book.keeping.db.dao.CostType

class IndexViewModel : ViewModel() {

    val costList = listOf(
        Cost(123, CostType.FavorType(), 1, 31.0f),
        Cost(1, CostType.FavorType(), 0, 21.0f),
        Cost(2, CostType.FavorType(), 0, 23.0f),
        Cost(3, CostType.FavorType(), 0, 23.0f, day = 13, description = "娱乐"),
        Cost(4, CostType.Bus(), 0, 23.0f, day = 12),
        Cost(5, CostType.Fruits(), 0, 23.0f, day = 12),
        Cost(6, CostType.Motion(), 0, 23.0f, day = 12),
        Cost(7, CostType.Restaurant(), 0, 23.0f, day = 12),
        Cost(8, CostType.Play(), 0, 23.0f, day = 11),
        Cost(9, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(10, CostType.Shop(), 0, 23.0f, day = 11),
        Cost(11, CostType.Snacks(), 0, 23.0f, day = 10),
        Cost(12, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(13, CostType.DayUse(), 0, 23.0f, day = 11),
        Cost(14, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(15, CostType.Snacks(), 0, 23.0f, day = 10),
        Cost(16, CostType.Vegetable(), 0, 23.0f, day = 11),
        Cost(17, CostType.Snacks(), 0, 23.0f, day = 10),
        Cost(18, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(19, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(20, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(21, CostType.Snacks(), 0, 23.0f, day = 10),
        Cost(22, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(23, CostType.Snacks(), 0, 23.0f, day = 10),
        Cost(24, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(25, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(26, CostType.Snacks(), 0, 23.0f, day = 11),
        Cost(27, CostType.Snacks(), 0, 23.0f, day = 10),
    )

    fun getCostList(): Map<Int, Triple<Double, Double, List<Cost>>> {
        return costList.groupBy { it.day }.mapValues { (_, costs) ->
            val profit = costs.filter { it.type == 1 }.sumOf { it.money.toDouble() }
            val loss = costs.filter { it.type == 0 }.sumOf { it.money.toDouble() }
            Triple(profit, loss, costs)
        }
    }


}